package com.zmn.mcc.admin.controller.role.change.log;

import com.zmn.common.dictionary.GlobalDict;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.mcc.admin.controller.role.RoleBaseController;
import com.zmn.mcc.business.interfaces.role.RoleChangeLogBService;
import com.zmn.mcc.business.interfaces.staff.StaffBService;
import com.zmn.mcc.common.dto.role.McRoleChangeLogQuery;
import com.zmn.mcc.model.entity.role.McRole;
import com.zmn.mcc.model.entity.role.McRoleChangeLog;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author heguanghua
 * @since 2020/04/15 10:53
 */
@Controller
@RequestMapping("/role/change/log")
public class RoleChangeLogListController extends RoleBaseController {
    @Resource
    private StaffBService staffBService;
    @Resource
    private RoleChangeLogBService roleChangeLogBService;


    /**
     * 角色异动日志
     */
    @RequestMapping(value = "list")
    public String list(HttpServletRequest request,
                       @ModelAttribute McRoleChangeLogQuery query,
                       Model model) {
        if (StringUtil.isNotBlank(query.getCreateTimeRange())) {
            String[] createTimeRangeArray = query.getCreateTimeRange().split("-");
            query.setCreateTimeStart(createTimeRangeArray[0].trim() + " 00:00:00");
            query.setCreateTimeEnd(createTimeRangeArray[1].trim() + " 23:59:59");
        }
        List<McRoleChangeLog> items = roleChangeLogBService.listPageMcRoleChangeLog(query);

        McRole obj = !NumberUtil.isNullOrZero(query.getRoleId()) ? roleService.findByKey(query.getRoleId()) : new McRole();

        model.addAttribute("items", items);
        model.addAttribute("vo", query);

        model.addAttribute("obj", obj);

        //model.addAttribute("yesno", GlobalDict.getYesOrNoList());
        model.addAttribute("statuses", GlobalDict.getStatusList(true));

        // 是否拥有"权限管理员角色"
        model.addAttribute("isAssignAdmin", staffBService.isAssignAdmin(getStaffId()));

        return "role/change/log/list";
    }

}
